<?php include COMMON_PATH.'/index/header.html' ?>
<!--考试答题-->
<div class="home-bot-wrap main-content question-wrap clearfix">
    <div class="title clearfix">
        <span class="fl"><?=$answer['name']?>（共<?=count($answer['lists'])?>题）</span>
    </div>
    <div class="as-wrap">
        <ul class="question-list-wrap">
            <?php foreach($answer['lists'] as $k=>$v):?>
                <li data-qid="<?=$v['qid']?>" data-type="<?=$v['type']?>">
                    <div class="questions-item clearfix">
                        <div ><span class="num-now-wrap fl"><?=$k+1?>、</span></div><p class="question"><?=$v['topic']?>
                        <?php if($v['type'] == 2):?>
                        (多选题)
                        <?php else:?>
                        (单选题)
                        <?php endif;?>
                        <span class="user-selected"></span></p>
                    </div>
                    <div class="option-item  clearfix" data-eq="1" data-option="A" style="">
                        <span>A、</span><p class="option-text"><?=$v['option_a']?></p>
                    </div>
                    <div class="option-item clearfix" data-eq="2" data-option="B">
                        <span>B、</span><p class="option-text"><?=$v['option_b']?></p>
                    </div>
                    <div class="option-item clearfix" data-eq="3" data-option="C">
                        <span>C、</span><p class="option-text"><?=$v['option_c']?></p>
                    </div>
                    <div class="option-item clearfix" data-eq="4" data-option="D">
                        <span>D、</span><p class="option-text"><?=$v['option_d']?></p>
                    </div>
                </li>
            <?php endforeach;?>
        </ul>
        <span id="question-submit">提交</span>
    </div>
</div>
<?php include COMMON_PATH.'/index/footer.html' ?>
<script>
    navActive(1);

    $(function(){
        layui.use(['element','layer','form', 'laypage', 'laydate'], function(){
            var layer = layui.layer //获得layer模块
                    ,laypage = layui.laypage //获得laypage模块
                    ,laydate = layui.laydate //获得laydate模块
                    ,form = layui.form //获得laydate模块
                    ,element = layui.element;

            var $li_item = $('.question-list-wrap li .option-item');

            $li_item.hover(function(){
                $(this).addClass('active').siblings('.option-item').not('.activeA').removeClass('active');
            },function(){
                $(this).removeClass('active')
            });

            $li_item.on('click',function(){
                if($(this).parent('li').attr('data-type')==2){
                    $(this).toggleClass('activeA');
                    var option_item_active = $(this).parent('li').find('.activeA');
                    var answer = '',eq_str = '';
                    $.each(option_item_active,function(){
                        answer += $(this).attr('data-option')+',';
                        eq_str+=$(this).attr('data-eq')+',';
                    });
                    answer = answer.slice(0,answer.length-1);
                    eq_str = eq_str.slice(0,eq_str.length-1);
                    $(this).parent('li').attr('data-eq',eq_str);
                    $(this).siblings('.questions-item').find('.user-selected').html(answer);
                }else {
                    $(this).parent('li').attr('data-eq',$(this).attr('data-eq'));
                    $(this).addClass('activeA').siblings('.option-item').removeClass('activeA');
                    $(this).siblings('.questions-item').find('.user-selected').html($(this).attr('data-option'));
                }
            });

            $('#question-submit').on('click',function(){
                var ques_li = $('.question-list-wrap li');
                var llid = iService.getQueryString('llid');
                var result = [];
                $.each(ques_li,function(e){
                    if(!$(this).find('.activeA').length){
//                        layer.msg('第'+(e+1)+'题未答', {icon: 2,anim: 6,time:2*1000});
                        layer.open({
                            type: 1,
//                          title: false, //不显示标题栏
                            content: '<div style="padding: 20px 100px;">第'+(e+1)+'题未答</div>'  //这里content是一个普通的String
                            ,id: 'layerTips' //防止重复弹出
                            ,btn: '确定'
                            ,btnAlign: 'c' //按钮居中
                            ,shade: 0 //不显示遮罩
                            ,yes: function(){
                                layer.closeAll();
                            }

                        });
                        return false;
                    }else {
                        result.push({'qid':$(this).attr('data-qid'),'correct':$(this).attr('data-eq')});
                        if(e==ques_li.length-1){
                            //提交题目00
                            console.log(1);
                            var param = {
                                url:'question/answerPost',
                                data:{
                                    llid: llid,
                                    result: JSON.stringify(result)
                                }
                            };
                            $.JsonRpc(param,function(data){
                                console.log(data);
                                if(data.code!=200){
                                    layer.msg(data.data.message, {icon: 2,anim: 6,time:2*1000});
                                }else {
                                    layer.msg(data.data.message, {icon: 1,anim: 6,time:2*1000});
                                    setTimeout(function(){
                                        location.reload();
//                                      location.href = 'result?llid='+llid;
                                    },1000);
                                }
                            });
                        }
                    }
                });
            });
        });
    })
</script>
</html>



















